layui.use(['layer','element','form','layedit','carousel','flow','util'],function(){
    var element = layui.element;
    var layer = layui.layer;
    var form = layui.form;
    var layedit = layui.layedit;
    var carousel = layui.carousel;
    var flow = layui.flow;
    var util = layui.util;
    var $ = layui.jquery;
    // 登录
    form.verify({
        nickname:function(value,item){
            if( $.trim(value) == '' ){
                return '昵称不能为空！';
            }
        },
        username:function(value,item){
            if( $.trim(value) == '' ){
                return '登录名不能为空！';
            }
        },
        vertify:function(value,item){
            if( $.trim(value) == '' ){
                return '验证码不能为空！';
            }
        },
        password:[/^[\S]{6,12}$/,'密码必须6到12位，且不能出现空格!']
    });
    //登录窗口
    $(".userLoginBtn").on("click",function(){
        $("#userLogin").removeClass('layui-hide');
        $("#userReg").addClass('layui-hide');
    });
    //注册窗口
    $(".userRegBtn").on("click",function(){
        $("#userLogin").addClass('layui-hide');
        $("#userReg").removeClass('layui-hide');
    });
    //关闭窗口
    $(".model-box .cls").on("click",function(){
        $(this).parents('.model-box').addClass("layui-hide")
    });

    // 轮播图
    carousel.render({
        elem: '#carousel'
        ,width: '100%' //设置容器宽度
        ,arrow: 'always' //始终显示箭头
        //,anim: 'updown' //切换动画方式
    });
    // 轮播
    function playAnnouncement() {
        var index = 0;
        var $announcement = $('.fl-tips-container>span');
        //自动轮换
        setInterval(function () {
            index++;    //下标更新
            if (index >= $announcement.length) {
                index = 0;
            }
            $announcement.eq(index).stop(true, true).fadeIn().siblings('span').fadeOut();  //下标对应的图片显示，同辈元素隐藏
        }, 5000);
    }
    playAnnouncement();
    // // 流加载
    // flow.load({
    //     elem: '#fl-flow-article'
    //     ,isAuto:true
    //     ,isLazyimg:false
    //     ,done: function(page,next){//到达临界点（默认滚动触发），触发下一页
    //         //模拟数据插入
    //         setTimeout(function(){
    //             var list = [];
    //             var html ='';
    //             html+='<div class="article shadow">'
    //             html+=    '<div class="article-left">'
    //             html+=         '<img src="../image/22.jpg" alt="【Welcome to .NET Core】ASP.NET Core中间件介绍">'
    //             html+=     '</div>'
    //             html+=     '<div class="article-right">'
    //             html+=         '<div class="article-title">'
    //             html+=             '<i class="icon-stick">顶</i>'
    //             html+=             '<a href="/Article/Detail/LY08302213354352">【Welcome to .NET Core】ASP.NET Core中间件介绍</a>'
    //             html+=         '</div>'
    //             html+=         '<div class="article-abstract">'
    //             html+=             '.NET Core入门系列第二篇。对ASP.NET Core的新模块——中间件做简单的介绍和实践。'
    //             html+=         '</div>'
    //             html+=     '</div>'
    //             html+=     '<div class="clear"></div>'
    //             html+=     '<div class="article-footer">'
    //             html+=         '<span>'
    //             html+=             '<i class="fa fa-clock-o"></i>&nbsp;&nbsp;2017-08-30'
    //             html+=         '</span>'
    //             html+=         '<span class="article-author">'
    //             html+=             '<i class="fa fa-user"></i>&nbsp;&nbsp;Absolutely'
    //             html+=         '</span>'
    //             html+=         '<span>'
    //             html+=             '<i class="fa fa-tag"></i>&nbsp;&nbsp;'
    //             html+=             '<a href="/Article/Category/LY08252038435254">.NET Core</a>'
    //             html+=         '</span>'
    //             html+=         '<span class="article-viewinfo">'
    //             html+=             '<i class="fa fa-eye"></i>&nbsp;1358'
    //             html+=         '</span>'
    //             html+=         '<span class="article-viewinfo">'
    //             html+=             '<i class="fa fa-comment"></i>&nbsp;16'
    //             html+=         '</span>'
    //             html+=     '</div>'
    //             html+= '</div>';
    //             for(var i = 0;i < 5;i++){
    //                 list.push(html);
    //             }
    //             //执行下一页渲染，第二参数为：满足“加载更多”的条件，即后面仍有分页
    //             //pages为Ajax返回的总页数，只有当前页小于总页数的情况下，才会继续出现加载更多
    //             next(list.join(''), page < 2); //假设总页数为 10
    //         },500)
    //     }
    // })
    // 工具集
    util.fixbar({
        bar1:'&#xe641;'
        ,click:function(type){
            if(type === 'bar1'){
                var sear = new RegExp('layui-hide');
                if (sear.test($('.fl-share').attr('class'))) {
                    shareIn();
                } else {
                    shareOut();
                }
            }
        }
    })
    //子栏目导航点击事件
    $('.child-nav span').click(function () {
        // layer.msg('切换到相应栏目');
        $(this).addClass('child-nav-btn-this').siblings().removeClass('child-nav-btn-this');
    });
     //侧边导航开关点击事件
    $('.fl-navicon').click(function () {
        var sear = new RegExp('layui-hide');
        if (sear.test($('.fl-nav-left').attr('class'))) {
            leftIn();
        } else {
            leftOut();
        }
    });
    //侧边导航遮罩点击事件
    $('.fl-mask').click(function () {
        leftOut();
    });
    // 右侧点击导航分类
    $('.fl-category-toggle').click(function (e) {
        e.stopPropagation();
        categroyIn();
    });
    $('.fl-body,.fl-footer').click(function () {
        shareOut();
        categoryOut();
    });
    //显示百度分享
    function shareIn() {
        $('.fl-share').unbind('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend');
        $('.fl-share').removeClass('shareOut');
        $('.fl-share').addClass('shareIn');
        $('.fl-share').removeClass('layui-hide');
        $('.fl-share').addClass('layui-show');
    }
    //隐藏百度分享
    function shareOut() {
        $('.fl-share').on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
            $('.fl-share').addClass('layui-hide');
        });
        $('.fl-share').removeClass('shareIn');
        $('.fl-share').addClass('shareOut');
        $('.fl-share').removeClass('layui-show');
    }
     //显示侧边导航
    function leftIn() {
        $('.fl-mask').unbind('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend');
        $('.fl-nav-left').unbind('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend');

        $('.fl-mask').removeClass('maskOut');
        $('.fl-mask').addClass('maskIn');
        $('.fl-mask').removeClass('layui-hide');
        $('.fl-mask').addClass('layui-show');

        $('.fl-nav-left').removeClass('leftOut');
        $('.fl-nav-left').addClass('leftIn');
        $('.fl-nav-left').removeClass('layui-hide');
        $('.fl-nav-left').addClass('layui-show');
    }
    //隐藏侧边导航
    function leftOut() {
        $('.fl-mask').on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
            $('.fl-mask').addClass('layui-hide');
        });
        $('.fl-nav-left').on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
            $('.fl-nav-left').addClass('layui-hide');
        });

        $('.fl-mask').removeClass('maskIn');
        $('.fl-mask').addClass('maskOut');
        $('.fl-mask').removeClass('layui-show');

        $('.fl-nav-left').removeClass('leftIn');
        $('.fl-nav-left').addClass('leftOut');
        $('.fl-nav-left').removeClass('layui-show');
    }
    function categroyIn() {
        $('.fl-category-toggle').addClass('layui-hide');
        $('.fl-article-category').unbind('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend');
        $('.fl-article-category').removeClass('categoryOut');
        $('.fl-article-category').addClass('categoryIn');
        $('.fl-article-category').addClass('layui-show');
    }
    function categoryOut() {
        $('.fl-article-category').on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
            $('.fl-article-category').removeClass('layui-show');
            $('.fl-category-toggle').removeClass('layui-hide');
        });
        $('.fl-article-category').removeClass('categoryIn');
        $('.fl-article-category').addClass('categoryOut');
    }
})